//
//  YKRegisterViewController.m
//  WeChat
//
//  Created by 吴高烽 on 16/5/22.
//  Copyright © 2016年 吴高烽. All rights reserved.
//

#import "YKRegisterViewController.h"
#import "MBProgressHUD+HM.h"
@interface YKRegisterViewController ()
@property (weak, nonatomic) IBOutlet UITextField *registerUserF;
@property (weak, nonatomic) IBOutlet UITextField *registerPwdF;
@end

@implementation YKRegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)cancelRegister:(UIBarButtonItem *)sender {
    
}

- (IBAction)registerCustomer:(UIButton *)sender {
//   注册 发送jid给服务器
    [YKAccount shareAccount].registerUser =self.registerUserF.text;
    [YKAccount shareAccount].registerPwd =self.registerPwdF.text;
    [MBProgressHUD showMessage:@"注册中···"];
    [[YKXMPPTool shareYKXMPPTool]xmppRegister:^(XMPPResultTyep resultType) {
        [self handleXMPPResult:resultType];
    }];
    
}
-(void)handleXMPPResult:(XMPPResultTyep)resulType{
    dispatch_async(dispatch_get_main_queue(), ^{
         [MBProgressHUD hideHUD];
        if (resulType ==XMPPResultTyepRegisterSuccess) {
            [MBProgressHUD showSuccess:@"恭喜注册成功！"];
            [[YKAccount shareAccount] saveToSandBox];
            [UIStoryboard showInitialVCWithName:@"Login"];
    }else{
            [MBProgressHUD showError:@"用户名已注册！"];
    }
});

}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
